<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page session="false" %>
<%@ page isELIgnored ="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<style type="text/css">
.claro .dojoxCalendarEvent.Workday .bg {
  background-color: #00AA00;
}
.claro .dojoxCalendarEvent.Workday.Hovered .bg {
  background-color: #00FF00;
}
.claro .dojoxCalendarEvent.Workday.Selected .bg {
  background-color: #004400;
}
.claro .dojoxCalendarEvent.Holiday .bg {
  background-color: #0000AA;
}
.claro .dojoxCalendarEvent.Holiday.Hovered .bg {
  background-color: #0000FF;
}
.claro .dojoxCalendarEvent.Holiday.Selected .bg {
  background-color: #000044;
}
</style>
<script type="text/javascript">
//<![CDATA[
           
(function(){
	if(typeof Calendar === "undefined" ){
		Calendar = {
			ruleFindByYear:function(year){
				Calendar.storeRule = new dojox.data.QueryReadStore({url:'../../organization/calendar/calruleByYear?oid='+Calendar.selectedOrgId+'&year='+year});
				grid_calendar_rule.setStore(Calendar.storeRule);
			},
			ruleRefresh:function(){
				Calendar.storeRule = new dojox.data.QueryReadStore({url:'../../organization/calendar/calrule?oid='+Calendar.selectedOrgId});
				grid_calendar_rule.setStore(Calendar.storeRule);
			},
			rulePriorityUp:function(){
				if(Calendar.selectedOrgId == ""){
					this.dlg=dijit.byId("rulePriorityUpConfirm");
					if(!this.dlg)this.dlg=new dijit.Dialog({
						id:"rulePriorityUpConfirm",
						title: KppModule.commonResource.hint,
						style: "padding:0px;width:300px;height:100px;background-color:#FFF;"});
						this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+Organization._resource.rulePriorityUpConfirm+"</div>");
					this.dlg.show();
				}else{
					dojo.rawXhrPost({
						url:"../../organization/calendar/up.do?id="+Calendar.selectedRuleId,
						postData:"",
						handleAs:'text',
						load:function(response){
							Calendar.ruleRefresh();
						},
						error:function(){
						}
					});
				}
			},
			callNewRule: function(){
				if(Calendar.selectedOrgId == ""){
					this.dlg=dijit.byId("calendarRuleConfim");
					if(!this.dlg)this.dlg=new dijit.Dialog({
						id:"calendarRuleConfim",
						title: KppModule.commonResource.hint,
						style: "padding:0px;width:300px;height:100px;background-color:#FFF;"});
						this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+Organization._resource.calendarRuleConfim+"</div>");
					this.dlg.show();
				}else{
					$ku.showDialog({
						id:"dialog_org_calrule_new",
						url:"../../organization/calendar/"+Calendar.selectedOrgId+"/calrulenew.html",
						title:$ksub(KppModule.commonResource.operCreate,[Organization._resource.rule]),
						resource:Organization._resource,
						style:"width:450px;height:240px;"});
				}
	        },
	        callEditRule: function(){
				if(Calendar.selectedRuleId == ""){
					this.dlg=dijit.byId("calendarRuleEditConfim");
					if(!this.dlg)this.dlg=new dijit.Dialog({
						id:"calendarRuleEditConfim",
						title: KppModule.commonResource.hint,
						style: "padding:0px;width:300px;height:100px;background-color:#FFF;"});
						this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+Organization._resource.calendarRuleEditConfim+"</div>");
					this.dlg.show();
				}else{
					$ku.showDialog({
						id:"dialog_org_calrule_edit",
						url:"../../organization/calendar/"+Calendar.selectedRuleId+"/calruleedit.html",
						title:$ksub(KppModule.commonResource.operEdit,[Organization._resource.rule]),
						resource:Organization._resourse,
						style:"width:450px;height:240px;"});
				}
	        },
	        callRemoveRule:function(){
	        	if(Calendar.selectedRuleId==""){
	        		this.dlg=dijit.byId("calendarRuleRemoveConfim");
					if(!this.dlg)this.dlg=new dijit.Dialog({
						id:"calendarRuleRemoveConfim",
						title: KppModule.commonResource.hint,
						style: "padding:0px;width:300px;height:100px;background-color:#FFF;"});
						this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+Organization._resource.calendarRuleRemoveConfim+"</div>");
					this.dlg.show();
	        	}else{
	        		this.dlg=dijit.byId("calRuleDelDlg");
					if(!this.dlg)this.dlg=new dijit.Dialog({
						id:"calRuleDelDlg",
						title: KppModule.commonResource.confirm,
						style: "padding:0px;width:300px;height:200px;background-color:#FFF;"});
						this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+KppModule.commonResource.removeCalRuleConfirm+"</div>"+
								"<div style=\"text-align:center\"><div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconDelete', id:'btn_calrule_del',showLabel:true, busyLabel:'"+KppModule.commonResource.removing+"'\">"+KppModule.commonResource.remove+
								"<script type=\"dojo/method\" event=\"onClick\" args=\"evt\">Calendar.removeRule('"+Calendar.selectedRuleId+"')<\/script>"+
								"</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
								"<div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconCancel', showLabel:true\">"+KppModule.commonResource.cancel +
									"<script type='dojo/method' event='onClick' args='evt'>dijit.byId('calRuleDelDlg').hide();<\/script></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
								"</div>"
					);
					this.dlg.show();
	        	}
	        },
	        removeRule:function(roleId){
	        	var options={
						domain:Organization._resource.rule,
						refresh:Calendar.ruleRefresh,
						url:"../../organization/calendar/"+roleId,
						button:dijit.byId("btn_calrule_del"),
						dialogId:"calRuleDelDlg",
						resource:Organization._resource
				};
				KppModule.restProxy(options).remove();
	        },
			callNewSchedule: function(){
				if(Calendar.selectedOrgId == ""){
					this.dlg=dijit.byId("calendarScheduleConfirm");
					if(!this.dlg)this.dlg=new dijit.Dialog({
						id:"calendarScheduleConfirm",
						title: KppModule.commonResource.hint,
						style: "padding:0px;width:300px;height:100px;background-color:#FFF;"});
						this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+Organization._resource.calendarScheduleConfirm+"</div>");
					this.dlg.show();
				}else{
					$ku.showDialog({
						id:"dialog_org_schedule_new",
						url:"../../organization/calendar/"+Calendar.selectedOrgId+"/calschedulenew.html",
						title:$ksub(KppModule.commonResource.operCreate,[Organization._resource.schedule]),
						resource:Organization._resource,
						style:"width:350px;height:200px;"});
				}
	        },
	        calendarStore:null,
	        calendarShow:function() {
	        	//日历展现
	        	var xhrArgs = {
	     			    url: "../../organization/event/eventbymonth?orgId="+Calendar.selectedOrgId+"&start="+Calendar.calendarDate.getTime(),
	     			    handleAs: "text",
	     			    load: function(datalist){
	     			    	eval("datalist="+datalist);
	     			    	for (var i=0;i<datalist.length;i++) {
	     			    		datalist[i].begin = new Date(datalist[i].begin);
	     			    		datalist[i].end = new Date(datalist[i].end);
	     			    	}
	     			    	Calendar.calendarStore = new dojo.store.Memory({data:datalist});
	     		            dijit.byId("calendar_calendar").set("store",new dojo.store.Observable(Calendar.calendarStore));
	     			    }, error: function(error){
	     			    }
	    	 	};
	    		dojo.xhrGet(xhrArgs); 
	        },
	        callRemoveItem:function() {
	        	if(Calendar.selectedOrgId == ""){
					this.dlg=dijit.byId("calendarScheduleConfirm");
					if(!this.dlg)this.dlg=new dijit.Dialog({
						id:"calendarScheduleConfirm",
						title: KppModule.commonResource.hint,
						style: "padding:0px;width:300px;height:100px;background-color:#FFF;"});
						this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+Organization._resource.calendarScheduleConfirm+"</div>");
					this.dlg.show();
				}else{
		        	this.dlg=dijit.byId("calScheduleDelDlg");
					if(!this.dlg)this.dlg=new dijit.Dialog({
						id:"calScheduleDelDlg",
						title: KppModule.commonResource.confirm,
						style: "padding:0px;width:300px;height:200px;background-color:#FFF;"});
						this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+$ksub(KppModule.commonResource.operDelete,[Calendar.selectedItemName+"("+Organization._resource.schedule+")"])+"</div>"+
								"<div style=\"text-align:center\"><div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconDelete', id:'btn_calrule_schedule_del',showLabel:true, busyLabel:'"+KppModule.commonResource.removing+"'\">"+KppModule.commonResource.remove+
								"<script type=\"dojo/method\" event=\"onClick\" args=\"evt\">Calendar.removeItem('"+Calendar.selectedItemId+"')<\/script>"+
								"</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
								"<div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconCancel', showLabel:true\">"+KppModule.commonResource.cancel +
									"<script type='dojo/method' event='onClick' args='evt'>dijit.byId('calScheduleDelDlg').hide();<\/script></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
								"</div>"
					);
					this.dlg.show();
				}
	        },
	        removeItem:function(id) {
	        	var options={
						domain:Organization._resource.schedule,
						refresh:Calendar.calendarShow,
						url:"../../organization/calendar/schedule/"+id,
						button:dijit.byId("btn_calrule_del"),
						dialogId:"calScheduleDelDlg",
						resource:Organization._resource
				};
				KppModule.restProxy(options).remove();
	        },
			gridRuleStructure:[
				{cells:[
					{field:"_item",name:KppModule.commonResource.sn,formatter:KppModule.sno,width:"40px",filterable:false},
					{field:"beginDate",name:Organization._resource.beginDate,formatter:$kt.escapeBlank,width:"200px",datatype:"string"},
					{field:"endDate",name:Organization._resource.endDate,formatter:$kt.escapeBlank,editable:true,width:"200px",datatype:"string"},
					{field:"affair",name:Organization._resource.affair,formatter:$kt.escapeBlank,editable:true,width:"auto",datatype:"string"}
				]}
			],
			selectedOrgId:'',
			selectedRuleId:'',
			selectedItemId:'',
			selectedItemName:'',
			calendarDate:new Date()
		};
		Calendar.storeRule = new dojox.data.QueryReadStore({url:'../../organization/calendar/calrule?oid='+Calendar.selectedOrgId});
		Calendar.orgStore = new dojo.store.Memory({
			data:[
			{id:"root",name:KppModule.commonResource.all,parent:""}
			//<c:forEach items="${orgs}" var="org" >
			,{id:"${org.id}",name:"${org.label}",parent:"${org.parent==null?'root':org.parent.id}"}
			//</c:forEach>
			],getChildren:function(object){
				return this.query({parent: object.id});
			}
		});
		Calendar.calendarShow();
	};
	$kdom.appendDojoProp("ep_calendar_org","title",Organization._resource.organization);
	$kdom.appendDojoProp("cp_calendar_nav","content","<img class=\"icon_s_co icon_s_co_calendar_month\" src=\"${pageContext.request.contextPath}/assets/images/blank.gif\" /><span>"+Organization._resource.calendar+"</span>");
	$kdom.appendDojoProp("btn_calendar_new","label",$ksub(KppModule.commonResource.operCreate,[Organization._resource.schedule]));
	$kdom.appendDojoProp("btn_calendar_remove","label",$ksub(KppModule.commonResource.operDelete,[Organization._resource.schedule]));
	$kdom.appendDojoProp("btn_calendar_refresh","label",KppModule.commonResource.refresh);
	$kdom.appendDojoProp("btn_calendar_setup","label",$ksub(KppModule.commonResource.operSetup,[Organization._resource.rule]));
	$kdom.appendDojoProp("btn_calendar_rule_refresh","label",KppModule.commonResource.refresh);
	$kdom.appendDojoProp("btn_calendar_rule_new","label",$ksub(KppModule.commonResource.operCreate,[Organization._resource.rule]));
	$kdom.appendDojoProp("btn_calendar_rule_remove","label",$ksub(KppModule.commonResource.operDelete,[Organization._resource.rule]));
	$kdom.appendDojoProp("btn_calendar_rule_edit","label",$ksub(KppModule.commonResource.operEdit,[Organization._resource.rule]));
	$kdom.appendDojoProp("btn_calendar_rule_priorityup","label",Organization._resource.priorityup);
	$kdom.appendDojoProp("btn_calendar_back","label",$ksub(KppModule.commonResource.operBack,[Organization._resource.calendar]));
	
})();

//]]>
</script>

<span style="display:none">To solve IE7/8 script event tag problem.</span>
<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'titlebar',liveSplitters:true" class="contentWrapper" style="margin:-2px;height:100%">
	<div id="cp_calendar_nav" data-dojo-type="dijit/layout/ContentPane"  data-dojo-props="region:'top'" class="contentWrapperRight contentPaneNav" style="border:none;margin:-5px;padding:10px 0 10px 10px;background-color:transparent">
	</div>
	<div id="ep_calendar_org" data-dojo-type="dojox/layout/ExpandoPane" data-dojo-props="region:'left'" style="width:200px;">
			<div data-dojo-type="dijit/tree/ObjectStoreModel" data-dojo-id="calendarOrgModel"
				  data-dojo-props="store: Calendar.orgStore, query: {id: 'root'}"></div>
			<div data-dojo-type="dijit/Tree" data-dojo-props="model: calendarOrgModel, showRoot: true,autoExpand:false,getIconClass:function(item,opened){return (!item || item.type=='category') ? (opened ? 'dijitFolderOpened' : 'dijitFolderClosed') : (item.icon?item.icon:'dijitLeaf');}" style="border:1px solid #769DC0;background-color:white;">
				<script type="dojo/on" data-dojo-event="click" data-dojo-args="item">
					Calendar.selectedOrgId = item.id;
					if(dijit.byId("calendar_calendar").selected) {
						Calendar.calendarShow();
					} else {
						Calendar.ruleRefresh();
					}
				</script>
			</div>
	</div>
	<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="region:'center',design:'titlebar',liveSplitters:true" >
		<div id="stack_calendar_toolbar" data-dojo-type="dijit/layout/StackContainer"  data-dojo-props="region:'top'" >
			<div id="toolbar_calendar_calendar" data-dojo-type="dijit/Toolbar">
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_setup" data-dojo-props="iconClass:'icon_s_office icon_s_office_table_config'" style="float:right;">
					<script type="dojo/on" data-dojo-event="click">
					dijit.byId("stack_calendar_toolbar").selectChild("toolbar_calendar_rule",true);
					dijit.byId("stack_calendar_detail").selectChild("grid_calendar_rule",true);
					</script>
				</div>
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_refresh" onclick="Calendar.calendarShow()" data-dojo-props="iconClass:'commonAppIcon16 commonAppIcon16refresh'" style="float:right;">
				</div>
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_new" onclick="Calendar.callNewSchedule()" data-dojo-props="iconClass:'icon_s_co icon_s_co_calendar_new'">
				</div>
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_remove" onclick="Calendar.callRemoveItem()" data-dojo-props="iconClass:'icon_s_co icon_s_co_calendar_remove'">
				</div>
			</div>
			<div id="toolbar_calendar_rule" data-dojo-type="dijit/Toolbar">
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_back" data-dojo-props="iconClass:'icon_s_co icon_s_co_calendar_go'" style="float:right;">
					<script type="dojo/on" data-dojo-event="click">
						dijit.byId("stack_calendar_toolbar").selectChild("toolbar_calendar_calendar",true);
						dijit.byId("stack_calendar_detail").selectChild("calendar_calendar",true);
					</script>
				</div>
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_rule_refresh" onclick="Calendar.ruleRefresh()" data-dojo-props="iconClass:'commonAppIcon16 commonAppIcon16refresh'" style="float:right;">
				</div>
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_rule_new" onclick="Calendar.callNewRule()" data-dojo-props="iconClass:'icon_s_office icon_s_office_table_new'">
				</div>
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_rule_edit" onclick="Calendar.callEditRule()" data-dojo-props="iconClass:'icon_s_office icon_s_office_table_edit'">
				</div>
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_rule_remove" onclick="Calendar.callRemoveRule()" data-dojo-props="iconClass:'icon_s_office icon_s_office_table_remove'">
				</div>
				<div data-dojo-type="dijit/form/Button" id="btn_calendar_rule_priorityup" onclick="Calendar.rulePriorityUp()" data-dojo-props="iconClass:'icon_s_office icon_s_office_table_insertrow'">
				</div>
				<select name="slct_rule_year" data-dojo-type="dijit/form/Select">
					<c:forEach var="year" varStatus="status" begin="${currentYear-5}" end="${currentYear+20}">
					    <option value="${year}" ${year==currentYear?"selected='selected'":""}>${year}</option>
				    </c:forEach>
				    <script type="dojo/on" data-dojo-event="change" data-dojo-args="evt">
						Calendar.ruleFindByYear(evt);
					</script>
				</select>
			</div>
		</div>
		<div id="stack_calendar_detail" data-dojo-type="dijit/layout/StackContainer" data-dojo-props="region:'center'" style="border:none" >
			<div id="calendar_calendar" data-dojo-type="dojox/calendar/Calendar"
			     data-dojo-props="date: new Date(),startTimeAttr:'begin',endTimeAttr:'end',dateInterval:'day',cssClassFunc: function(item){return item.type;}"
			     style="position:relative;width:100%;height:100%">
			     <script type="dojo/on" data-dojo-event="itemClick" data-dojo-args="evt">
					Calendar.selectedItemId = evt.item.source;
					Calendar.selectedItemName = evt.item.summary;
				 </script>
				 <script type="dojo/on" data-dojo-event="timeIntervalChange" data-dojo-args="evt">
					Calendar.calendarDate = evt.startTime;
					Calendar.calendarShow();
				 </script>
			</div>
			<div id="grid_calendar_rule" data-dojo-type="dojox/grid/DataGrid" data-dojo-id="grid_calendar_rule"
				data-dojo-props="structure:Calendar.gridRuleStructure,canSort:function(){return false;},store:Calendar.storeRule,style:'margin:2px;'" >
				<script type="dojo/on" data-dojo-event="selected" data-dojo-args="evt">
					var table=dijit.byId("grid_calendar_rule");
					var index=evt;
					var row=table.getItem(index);
					Calendar.selectedRuleId=row.i.id;
				</script>
			</div>
		</div>
	</div>
</div>